

var api = require('../../utils/api.js');
var app = getApp();


Page({

    /**
     * 页面的初始数据
     */
    data: {
        latitude:'',
        longitude:'',
        array:['回访','售后','催款' ,'跟进','约谈','成交'],
        array_t:'',
        desc:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that=this;
        api.post({
            url: 'client/getinfobyid',
            data: {id:options.id},
            success: data => {
               console.log(data);
               that.setData({
                   info:data.data
               })
            }
        });
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        var that=this;
        wx.getLocation({
            type: 'gcj02', 
            success: function(res) {
              console.log('定位成功', res.latitude, res.longitude);

              that.setData({
                latitude:res.latitude,
                longitude:res.longitude
              })
        
            },
            fail: function(err) {
              console.error('定位失败', err);

            }
          });
    },

    bindPickerChange(ret){
        console.log(ret);
        var i=ret.detail.value;

        var array=this.data.array;
        console.log(i);
        var array_t=array[i];

        this.setData({
            array_t:array_t
        })

    },

    seedesc(res){
        this.setData({
            desc:res.detail.value
        })
    },

    //提交拜访信息
    submits(){

        var id=this.data.info.id;
        var array_t=this.data.array_t;
        var desc=this.data.desc;
        
        var latitude=this.data.latitude;
        var longitude=this.data.longitude;
   

        var that=this;
        api.post({
            url: 'client/informationclient',
            data: {id:id,array_t:array_t,desc:desc,longitude:longitude,latitude:latitude},
            success: data => {
               console.log(data);
                wx.showToast({
                  title: data.msg,
                  icon:'none'
                })

                if(data.code==1){
                    setTimeout(() => {
                        wx.navigateBack();
                    }, 1200);
                   
                }

               

            }
        });

    }

})